/**
 * 
 */
package com.google.code.cana.service;

import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import com.google.code.cana.pojo.financeiro.ItemExtrato;

/**
 * @author Rodrigo Barbosa Lira
 * @author Samuel de Barros
 * 
 */
public class RelatorioServiceImpl implements RelatorioService {

	private CompraService compraService;

	private GratificacaoService gratificacaoService;

	private RetiradaService retiradaService;

	private VendaService vendaService;
	
	/**
	 * @param compraService
	 *            the compraService to set
	 */
	public void setCompraService(CompraService compraService) {
		this.compraService = compraService;
	}

	/**
	 * @param gratificacaoService
	 *            the gratificacaoService to set
	 */
	public void setGratificacaoService(GratificacaoService gratificacaoService) {
		this.gratificacaoService = gratificacaoService;
	}

	/**
	 * @param retiradaService
	 *            the retiradaService to set
	 */
	public void setRetiradaService(RetiradaService retiradaService) {
		this.retiradaService = retiradaService;
	}

	/**
	 * @param vendaService
	 *            the vendaService to set
	 */
	public void setVendaService(VendaService vendaService) {
		this.vendaService = vendaService;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.code.cana.service.RelatorioService#getRelatorioFinanceiro(java.util.Date,
	 *      java.util.Date)
	 */
	@SuppressWarnings("unchecked")
	public List<ItemExtrato> getRelatorioFinanceiro(Date dataInicio,
			Date dataTermino) {
		List result = new LinkedList();
		result.addAll(compraService.recuperarPorPeriodo(dataInicio, dataTermino));
		result.addAll(gratificacaoService.recuperarPorPeriodo(dataInicio, dataTermino));
		result.addAll(retiradaService.recuperarPorPeriodo(dataInicio, dataTermino));
		result.addAll(vendaService.recuperarPorPeriodo(dataInicio, dataTermino));
		
		Collections.sort(result);
		
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.code.cana.service.RelatorioService#getRelatorioFinanceiro(java.util.Date)
	 */
	public List<ItemExtrato> getRelatorioFinanceiro(Date dataInicio) {
		return getRelatorioFinanceiro(dataInicio, new Date());
	}

}
